local skel = fk.CreateSkill {
  name = "emo__cangqiongxj",
  tags = {Skill.Limited},
  dynamic_desc = function (self, player, lang)
    if player:usedSkillTimes(self.name, Player.HistoryGame) == 0 then
      return "emo__cangqiongxj_damage:"..(1+player:getMark("emo__cangqiongxj_damage"))
    else
      return "emo__cangqiongxj_rest:"..(1+player:getMark("emo__cangqiongxj_damage"))..":"..(3-player:getMark("emo__cangqiongxj_rest"))
    end
  end,
}

skel:addEffect("active", {
  anim_type = "offensive",
  prompt = function (self, player, selected_cards, selected_targets)
    return "#emo__cangqiongxj:::"..(1+player:getMark("emo__cangqiongxj_damage"))
  end,
  card_num = 0,
  min_target_num = 1,
  target_filter = function (self, player, to_select, selected)
    return true
  end,
  can_use = function (self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryGame) == 0
  end,
  times = function (self, player)
    return 1 - player:usedSkillTimes(skel.name, Player.HistoryGame)
  end,
  on_use = function (self, room, effect)
    local player = effect.from
    room:sortByAction(effect.tos)
    local num = 1 + player:getMark("emo__cangqiongxj_damage")
    for _, to in ipairs(effect.tos) do
      room:damage { from = player, to = to, damage = num, skillName = skel.name }
    end
  end,
})

skel:addEffect(fk.AfterSkillEffect, {
  is_delay_effect = true,
  mute = true,
  can_refresh = function(self, event, target, player, data)
    if player == target and player:usedSkillTimes(skel.name, Player.HistoryGame) > 0 then
      local skill = data.skill
      local skeleton = skill:getSkeleton()
      return not (skill.cardSkill or skill.global or skill.is_delay_effect) and skill:isPlayerSkill(player)
      and skeleton and skeleton.name ~= skel.name
    end
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    if player:getMark("emo__cangqiongxj_rest") >= 2 then
      room:setPlayerMark(player, "emo__cangqiongxj_rest", 0)
      room:addPlayerMark(player, "emo__cangqiongxj_damage", 1)
      player:setSkillUseHistory(skel.name, 0, Player.HistoryGame)
    else
      room:addPlayerMark(player, "emo__cangqiongxj_rest", 1)
    end
  end,
})


Fk:loadTranslationTable{
  ["emo__cangqiongxj"] = "苍穹星降",
  [":emo__cangqiongxj"] = "限定技，出牌阶段，你可以对任意名角色各造成一点伤害，当你发动三次其他技能后，此技能重置次数且伤害+1。",
  ["#emo__cangqiongxj"] = "苍穹星降：对任意名角色各造成%arg点伤害",
  [":emo__cangqiongxj_damage"] = "限定技，出牌阶段，你可以对任意名角色各造成{1}点伤害，当你发动三次其他技能后，此技能重置次数且伤害+1。",
  [":emo__cangqiongxj_rest"] = "限定技，出牌阶段，你可以对任意名角色各造成{1}点伤害，当你发动三次其他技能后，此技能重置次数且伤害+1（还剩{2}次！）。",
}


return skel
